package com.aoxin.service.impl.opm;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import com.aoxin.mapper.opm.SlfEmployeeMapper;
import com.aoxin.mapper.opm.SlfRoleEmployeeMapper;
import com.aoxin.model.dto.RoleEmployeeDto;
import com.aoxin.model.opm.SlfRoleEmployee;
import com.aoxin.service.inter.opm.RoleEmployeeService;
import com.aoxin.util.ErrorUtil;

@Service("roleEmployeeService")
public class RoleEmployeeServiceImpl implements RoleEmployeeService {

	@Autowired
	private SlfRoleEmployeeMapper slfRoleEmployeeMapper;

	@Autowired
	private SlfEmployeeMapper slfEmployeeMapper;

	@Override
	@Transactional
	public void insertSlfRoleEmployeeList(Integer roleId, List<Integer> employeeIds) {
		Assert.notNull(roleId, String.format(ErrorUtil.PARAMETER_NULL, "roleId"));
		Assert.notEmpty(employeeIds, String.format(ErrorUtil.PARAMETER_NULL, "employeeIds"));
		for (Integer integer : employeeIds) {
			if (this.slfRoleEmployeeMapper.getRecordCount(roleId, integer) < 1L) {
				SlfRoleEmployee slfRoleEmployee = new SlfRoleEmployee();
				slfRoleEmployee.setEmployeeId(integer);
				slfRoleEmployee.setRoleId(roleId);
				this.slfRoleEmployeeMapper.insertSelective(slfRoleEmployee);
			}
		}
	}

	@Override
	@Transactional
	public void deleteSlfRoleEmployeeByIds(List<Integer> roleEmployeeIds) {
		Assert.notEmpty(roleEmployeeIds, String.format(ErrorUtil.PARAMETER_NULL, "roleEmployeeIds"));
		this.slfRoleEmployeeMapper.deleteByPrimaryKeys(roleEmployeeIds);
	}

	@Override
	@Transactional
	public void updateSlfRoleEmployee(SlfRoleEmployee roleEmployee) {
		Assert.notNull(roleEmployee, String.format(ErrorUtil.PARAMETER_NULL, "roleEmployee"));
		this.slfRoleEmployeeMapper.updateByPrimaryKeySelective(roleEmployee);
	}

	@Override
	public SlfRoleEmployee getSlfRoleEmployee(Integer roleEmployeeId) {
		Assert.notNull(roleEmployeeId, String.format(ErrorUtil.PARAMETER_NULL, "roleEmployeeId"));
		return this.getSlfRoleEmployee(roleEmployeeId);
	}

	@Override
	public List<RoleEmployeeDto> getEmployeeListByRoleId(Map<String, Object> param) {
		List<RoleEmployeeDto> list =  this.slfRoleEmployeeMapper.getEmployeeListByRoleId(param);
		return list;
	}

}
